package com.jiazhong.boot.example.emp.controller;

import com.jiazhong.boot.commons.bean.Emp;
import com.jiazhong.boot.commons.util.JsonResult;
import com.jiazhong.boot.example.emp.service.EmpService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;

@Slf4j
@CrossOrigin
@RestController
@RequestMapping("/emp")
public class EmpController {
    @Resource
    private EmpService service;

    @GetMapping
    public JsonResult find(@RequestParam(name = "page", defaultValue = "1") int page, @RequestParam(name = "size", defaultValue = "10") int size) {
        return service.find(page, size);
    }

    @GetMapping("/find_job")
    public JsonResult findJob() {
        return service.findAllJob();
    }

    @GetMapping("/find_mgr")
    public JsonResult findMgr() {
        return service.findAllMgr();
    }

    @GetMapping("/find_ename_exists")
    public JsonResult findEnameExists(String ename) {
        return service.findEnameExists(ename);
    }

    @PostMapping
    public JsonResult save(Emp emp) {
        return service.save(emp);
    }

    @DeleteMapping
    public JsonResult remove(int id) {
        return service.removeById(id);
    }

    @DeleteMapping("/remove_batch")
    public JsonResult removeBatch(String ids) {
        log.info("ids:{}", ids);
        return service.removeByBatch(ids);
    }

    @PutMapping
    public JsonResult update(Emp emp) {
        return service.update(emp);
    }

    @PostMapping("/cascade")
    public JsonResult cascade(Emp emp, int page, int size) {
        log.info("emp:{}", emp);
        return service.findCascade(emp, page, size);
        //return find(1, 10);
    }
}
